
public class ReaderTest {

	// private SharedObject cpt;
	//static String myName;
	static String myName;
	
	public static void main(String argv[]) {
		
		if (argv.length != 1) {
			System.out.println("java ReaderTest <name>");
			return;
		}
		myName = argv[0];
		// initialize the system
		Client.init();
		// SharedObject c = null;
		// look up the IRC object in the name server
		// if not found, create it, and register it in the name server

		SharedObject c = Client.lookup("Counter");
		Counter cpt = null;
		if (c == null) {
			cpt = new Counter();
			c = Client.create(cpt);
			Client.register("Counter", c);
		}

		for(int i=0;i<2000000;i++) {

			c.lock_read();
			((Counter) (c.obj)).read();
			c.unlock();
			
			c.lock_write();
			((Counter) (c.obj)).increment(myName);
			c.unlock();
			
			c.lock_read();
			((Counter) (c.obj)).read();
			c.unlock();

		}

	}
}